﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>时间</title>
    <script type="text/javascript">
        var timeId;
        function showTime(){
            var d=new Date();
            var time=document.getElementById("tm");
            var year=d.getYear();
            var month=d.getMonth()+1;
            var day=d.getDate();
            var hour=d.getHours();
            var minute=d.getMinutes();
            var second=d.getSeconds();
            var secondTmp="0"+second;
            var secondNew=secondTmp.substring(secondTmp.length-2,secondTmp.length);
            var s=year+"-"+month+"-"+day+"   "+hour+":"+minute+":"+secondNew;
            time.value=s;
            timeId=setTimeout("showTime()",1000);
        }
        function stopTime(){
            clearTimeout(timeId);
        }
    </script>
</head>
<body>
<input type="text" id="tm" size="40">
<input type="button" value="显示" onClick="showTime()">
<input type="button" value="停止" onClick="stopTime()">
</body>
</html>